function ecog=ecogSubtractRefChan(ecog)
% ecog=ecogRemoveReference(ecog) subtract the reference channel from all other channels
%
% INPUT:
% ecog:         An ecog structure with field 'refChanTS'.
%
% OUTPUT:
% ecogRef:      An ecog structure. The reference channel is in a new field 
%

% 090601 JR wrote it

if ~isfield(ecog,'refChanTS') || isempty(ecog.refChanTS)
    error('ecogSubtractRefChan: no refernce channel available')
else
    % we loop over channels
    % this strategy requires a bit more time but saves memory
    for k=1:size(ecog.data,1)
        ecog.data(k,:,:)=squeeze(ecog.data(k,:,:))-squeeze(ecog.refChanTS);
    end
end
